package com.dotstone.chipism.adapter;

import java.util.List;

import com.dotstone.chipism.R;
import com.dotstone.chipism.bean.Device;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class WlanSelectAdapter extends BaseAdapter {

	private Context context;
    private List<Device> data;
    private HoldView holdView;
    public WlanSelectAdapter(Context _context, List<Device> data) {
        this.data = data;
        this.context = _context;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
    	if (view == null) {
			view = LayoutInflater.from(context).inflate(R.layout.item_select_wlan_list, null);
			holdView = new HoldView();
			holdView.deviceTv = (TextView) view.findViewById(R.id.device_name_tv);
			view.setTag(holdView);
		} else {
			holdView = (HoldView) view.getTag();
		}
		Device d = data.get(position);
		Log.i("wmy", ""+d.getDeviceName()+" "+d.getRole());
		if(d.getRole()==1){
			holdView.deviceTv.setTextColor(Color.parseColor("#54cbea"));
		}else{
			holdView.deviceTv.setTextColor(Color.parseColor("#777777"));
		}
		holdView.deviceTv.setText(d.getDeviceName());
		
        return view;
    }
    
    class HoldView {
		private TextView deviceTv;
	}

}
